package com.zxy.furns.filter;

import com.zxy.furns.utils.JDBCUtilsByDruid;

import javax.servlet.*;
import java.io.IOException;

/**
 * ClassName: Transaction
 * Package: com.zxy.furns.filter
 *
 * @Author zxy
 * @Create 2025/3/27 22:39
 * @Version 1.0
 * title:
 * Description:
 */
public class Transaction implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        try {
            filterChain.doFilter(servletRequest, servletResponse);
            JDBCUtilsByDruid.commit();
        } catch (Exception e) {
            JDBCUtilsByDruid.rollback();
            throw new RuntimeException(e);
        }


    }

    @Override
    public void destroy() {

    }
}
